package com.study.springcloudgateway.routeFilterFactory;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

/**
 * @description：自定义过滤
 * @author：李军荣
 * @date: 2021/2/7 11:11
 */
@Component
public class DefineGateWayFiltet extends AbstractGatewayFilterFactory<DefineGateWayFiltet.Config> {

    public DefineGateWayFiltet(){
        super(Config.class);
    }

    public static final String NAME_KEY = "name";


    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList(NAME_KEY);
    }



    @Override
    public GatewayFilter apply(Config config) {
        //pre post

        return ((exchange, chain) -> {
            return chain.filter(exchange).then(Mono.fromRunnable(()->{
                
            }));
        });
    }

    public static class Config {

        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

}
